package com.atguigu.eduservice.controller.front;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: guli_parent
 * @description:
 * @author: xuejingjing
 * @create: 2021-01-02 13:11
 **/

@RestController
@CrossOrigin
@RequestMapping("eduservice/teacherfront")
public class TeacherFromController {


    @Autowired
    private EduTeacherService eduTeacherService;

    @Autowired
    private EduCourseService eduCourseService;


    //1,分页查询讲师的方法
    //当前页，每页记录数
    //通过路径传值
    @PostMapping("getTeacherFrontList/{page}/{limit}")
    public R getTeacherFrontList(@PathVariable long page, @PathVariable long limit){

        Page<EduTeacher> pageTeacher = new Page<>(page,limit);
        //返回map
        Map<String,Object> map = eduTeacherService.getTeacherFrontList(pageTeacher);
        return R.ok().data(map);
    }

    @GetMapping("getTeacherFromInfo/{teacherId}")
    public  R getTeacherFrontInf(@PathVariable String teacherId){

        //1,根据讲师id查询讲师基本信息
        EduTeacher  eduTeacher = eduTeacherService.getById(teacherId);

        //2，根据讲师id查询所讲课程
        QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("teacher_id",teacherId);//where teacher_id = ?
        List<EduCourse> courseList = eduCourseService.list(wrapper);
      return R.ok().data("teacher",eduTeacher).data("courseList",courseList);

    }

}
